package com.sdsy.entity;


import com.sdsy.constant.ResultErrorInfo;

/**
 * 返回前端的实体对象
 */
public class ResultEntity {

	public static final int SUCCESS_CODE = 200;

	private boolean success ;
	private String message = "";
	private Object data ;
	private int code;

	public ResultEntity() {}
	
	public static ResultEntity success(){
		return new ResultEntity( SUCCESS_CODE,null,true ,null);
	}
	public static ResultEntity success(Object data){
		return new ResultEntity(SUCCESS_CODE,null, true ,data );
	}
//	public static ResultEntity success(String message ){
//		return new ResultEntity(SUCCESS_CODE, message, true, null );
//	}
	public static ResultEntity success(String message, Object data){
		return new ResultEntity(SUCCESS_CODE, message, true, data);
	}
	
	public static ResultEntity fail(ResultErrorInfo info){
		return new ResultEntity(info.getCode() , info.getMsg(),false, null);
	}
	public static ResultEntity fail(int code, String message ){
		return new ResultEntity(message,false, code);
	}
	public static ResultEntity fail(String code, String message , Object data){
		return new ResultEntity(message,false,data);
	}

	protected ResultEntity(String message, boolean success , Object data) {
		this.message = message;
		this.success =  success;
		this.data =  data;
	}

	protected ResultEntity(int code, String message, boolean success , Object data) {
		this.code = code;
		this.message = message;
		this.success =  success;
		this.data =  data;
	}
	
	protected ResultEntity(boolean isSuccess ) {
		this.success =  isSuccess;
	}
	
	protected ResultEntity(String message, boolean isSuccess, int code) {
		this.message = message;
		this.code = code;
		this.success =  isSuccess;
	}
	

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}
}
